﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Moq;
using LibraryForTest.BrainObj;

namespace UsingMoq
{
    [TestFixture]
    public class BrainTest
    {
        [Test]
        public void TouchHotIron_Yell()
        {
            var hand = new Mock<IHand>();
            var mouth = new Mock<IMouth>();

            hand.Setup(x => x.TouchIron(HotIron)).Throws(new BurnException());

            var brain = new Brain(hand.Object, mouth.Object);
            brain.TouchIron(new Iron { IsHot = true });

            mouth.Verify(x => x.Yell());
        }

        /// <summary>
        /// Parameter expectations tend to be quite verbose in Moq, so we provide a custom matcher.
        /// This needs a matcher method and a bool sibling method for evaluating the expectations.
        /// Calling this matcher is technically equivalent to <code>It.Is{Iron}(i => i.IsHot)</code>.
        /// </summary>
        public Iron HotIron
        {
            get { return Match<Iron>.Create<Iron>(x => x.IsHot); }
        }
    }
}
